#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#define LEN sizeof(struct People)
struct People{
	char name[10];
	char sex[4];
	int num;
	char email[20];
	char addr[30];
	struct People* next;
};
struct People* head=NULL;
struct Peopie* end=NULL;
void add_people(){
	system("cls");
	int count;
	printf("选择要添加联系人个数：\n");
	scanf("%d",&count);
	struct People *p1,*p2;
	p1=p2=(struct People*)malloc(LEN);
	int i=0;
	printf("--------------------------------------\n");
	if(head==NULL){
		head=p1;
	}
	else{
		end->next=p1;
	}
	while(count>0){
		printf("请输入第%d个联系人信息:\n",++i);
		printf("姓名：\n");
		scanf("%s",&p1->name);
		printf("性别：\n");
		scanf("%s",&p1->sex);
		printf("电话号码：\n");
		scanf("%d",&p1->num);
		printf("邮箱:\n");
		scanf("%s",&p1->email);
		printf("家庭地址：\n");
		scanf("%s",&p1->addr);
		count--;
		p2->next=p1;
		p2=p1;
		p1=(struct People*)malloc(LEN);
		system("cls");
	}
	p2->next=NULL;
	end=p2;
	printf("全部添加成功！\n");
	system("pause");
}

void views_people(){
	system("cls");
	struct People *pt;
	if(head!=NULL){
		for(pt=head;pt!=NULL;){
			printf("姓名：%s\n性别：%s\n电话号码:%d\n邮箱：%s\n家庭地址：%s\n",pt->name,pt->sex,pt->num,pt->email,pt->addr);
			pt=pt->next;
			printf("-------------------------------------------------------------\n");
		}
	}
	else{
		printf("该系统中无数据！");
	}
	system("pause");
}
void delall_people(){
	system("cls");
	printf("正在删除中...\n");
	system("pause");
	struct People *pt;
	for(pt=head;pt!=NULL;){
		struct People *temp=pt;
		pt=pt->next;
		free(pt);
	}
	head=NULL;
	end=NULL;
	printf("删除成功！\n");
	system("pause");
} 
void view_people(){
	system("cls");
	struct People *pt;
	printf("输入要查询的联系人名字：\n");
	char name[10];
	int flag=1;
	scanf("%s",&name);
	for(pt=head;pt!=NULL;){
		if(strcmp(pt->name,name)==0){
			printf("成功找到！\n");
			printf("姓名：%s\n性别：%S\n电话号码：%d\n邮箱:%s\n家庭地址:%s\n,pt->name,name");
			flag=0;
			break;
		}
		pt=pt->next;
	}
	if(flag){
		printf("不好意思，未找到！\n");
	}
	system("pause");
} 
void revise_People(){
	system("cls");
	struct People *pt;
	printf("输入要修改的联系人名字：\n");
	char name[10];
	int flag=1;
	scanf("%s",&name);
	for(pt=head;pt!=NULL;){
		if(strcmp(name,pt->name)==0){
			printf("成功找到！\n");
			printf("姓名：%s\n性别：%s\n电话号码:%d\n邮箱:%s\n家庭地址:%s\n",pt->name,name);
			flag=0;
			printf("请分别进行修改:\n");
			printf("姓名;\n");
			scanf("%s",&pt->name);
			printf("性别:\n");
			scanf("%s",&pt->sex);
			printf("电话号码:\n");
			scanf("%d",&pt->num);
			printf("邮箱:\n");
			scanf("%s",&pt->email);
			printf("家庭地址:\n");
			scanf("%s",&pt->addr);
			break;
		}
		pt=pt->next;
	}
	if(flag){
		printf("不好意思，未找到！\n");
	}
	system("pause");
}

void del_people(){
	system("cls");
	struct People *pt,*temp;
	pt=head;
	printf("请输入要删除的联系人：");
	char name[10];
	scanf("%s",&name);
	int flag=1;
	while(pt!=NULL){
		if(strcmp(name,pt->name)==0){
			if(pt==head){
				head=pt->next;
				flag=0;
				printf("删除成功!\n");
				system("pause");
			}
			else{
				printf("删除成功...\n");
				system("pause");
				temp->next=pt->next;
				free(pt);
				flag=0;
				break;
			}
		}
		temp=pt;
		pt=pt->next;
	}
	if(flag){
		printf("不好意思,未找到!\n");
		system("pause");
	}
}

void menu(){
	system("cls");
	printf("                         ------------------------------------                  ");
	printf("                         ----------通讯录管理系统------------                  ");
	printf("                         ----------1.录入信息    ------------                  ");
	printf("                         ----------2.查看全部信息------------                  ");
	printf("                         ----------3.查看单个信息------------                  ");
	printf("                         ----------4.删除全部信息------------                  ");
	printf("                         ----------5.删除单个信息------------                  ");
	printf("                         ----------6.修改单个信息------------                  ");
	printf("                         ----------7.退出系统    ------------                  ");
	int choice;
	printf("选择任一功能:\n");
}
